package com.yanqu.road.server.gameplayer.module.cricket.cmd;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.cricket.CricketModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CRICKET_DEFENSE_SET, desc = "防守阵容设置")
public class CricketDefenseSetCmd extends AbstractCommand {

    private CricketProto.CricketDefenseSetReqMsg reqMsg;

    private CricketProto.CricketDefenseSetRespMsg.Builder respMsgBuilder = CricketProto.CricketDefenseSetRespMsg.newBuilder();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        this.reqMsg = CricketProto.CricketDefenseSetReqMsg.parseFrom(packet.getBytes());
        this.respMsgBuilder.setRet(0);
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CricketModule cricketModule = player.getModule(CricketModule.class);
        ret = cricketModule.updateCricketDefense(reqMsg);
        this.respMsgBuilder.setRet(ret);
    }

    @Override
    public void sendData(GamePlayer player) {
        player.sendPacket(ClientProtocol.U_CRICKET_DEFENSE_SET, this.respMsgBuilder);

    }
}
